import { App, epclass } from '../../../../library/api/index'
Page({
  data: {
    txt: '',
    word: '',
    tip: 'blank',
    tipData: {}
  },
  onLoad: function(e) {
    App.jice.onLoad(e)
  },
  onReady: function() {
    App.jice.track('page', {
      pagepath: '/pages/me/epclass/apply/index',
      pageTitle: '我要报名',
      pageType: 'view'
    })
    App.logger({
      type: App.G.view,
      channel: App.G.channel,
      target: '我要报名'
    })
  },
  onShow: function() {
    App.jice.track('appshow')
  },
  apply: function(e) {
    var data = e.detail.value
    if(data.txt == '') {
      this.showErrorTip('请输入您要说的话~')
      return
    }
    setTimeout(() => {
      this.setData({
        txt: ''
      })
    }, 1000)
    epclass.userApply({txt: data.txt}, r => {
      this.showErrorTip(r.msg)
    })
  },
  userWord: function(e) {
    var data = e.detail.value
    if(data.word == '') {
      this.showErrorTip('请输入您要说的话~')
      return
    }
    setTimeout(() => {
      this.setData({
        word: ''
      })
    }, 1000)
    epclass.leaveWord({word: data.word}, r => {
      this.showErrorTip(r.msg)
    })
  },
  word: function() {
    this.setData({
      tip: 'leave_word',
      tipData: ''
    })
  },
  showErrorTip: function(msg) {
    this.setData({
      tip: 'error_tip',
      tipData: msg
    })
  },
  closeTip: function() {
    this.setData({
      tip: 'blank',
      tipData: {}
    })
  },
  onShareAppMessage: function() {
    return {
      title: '【专家学堂-美赞臣中国】与专家对话，做A+妈妈',
      desc: '听了这些资深专家的话，你也能成为A+妈妈哟~还不快来报名？',
      path: '/pages/me/epclass/apply/index',
      success: function() {
        epclass.shareLogger({
          class_id: 0,
          target: '我要上节目',
          action: 'appMessage'
        }, r => {
        })
      }
    }
    App.jice.track('onshare', {
      shareto: 'friend',
      title: '【专家学堂-美赞臣中国】与专家对话，做A+妈妈',
      path: '/pages/me/epclass/apply/index'
    })
  }
})
